[Top] [Prev] [Next] [Bottom] [Contents]

SaPutBlob

Inserts Blob data into a database table. (Sybase Only)

Synopsis

#include "WorkingDialog.h"
int SaPutBlob(int vendor,
					char *sv, 
					char *db,
					char *tab,
					char *col,
					int coltype,
					char *where,
					int totsize,
					void *chunk
					int chunksize,
					int flag);

Arguments

vendor
SGESYBASE is the only valid value.
sv
pointer to a string containing the destination server name
db
pointer to a string containing the destination database name
tab
pointer to a string containing the destination table name
col
pointer to a string containing the destination column name
coltype
SA_TEXT for text blobs or SA_BINARY for binary (image) blobs
where
pointer to a string containing a where clause that is guaranteed to return a unique row in a table when used with a select statement.
totsize
total size, in bytes, of blob, regardless of how many chunks are being passed.
chunk
a pointer to a buffer containing blob data to be inserted.
chunksize
size in bytes of the chunk currently being passed. If there is only one chunk, this should be the same as totsize.
flag
BLOB_ALL, BLOB_PART or BLOB_DONE

Return Values

0 means success

-1 means failure

Description

SaPutBlob will insert data incrementally into a blob column of a single row in a given table. The flag options are:

BLOB_ALL
The entire blob will be inserted in one trip to the database. With this flag, totsize and chunksize should be the same.
BLOB_PART
There will be multiple trips to the database when inserting this blob. This flag must be used for each chunk.
BLOB_DONE
This flag must be called after the entire blob has been inserted using BLOB_PART flag. This flag is not necessary when using the BLOB_ALL flag because BLOB_ALL inserts an entire blob in one pass.
To insert character-based blobs, use SA_TEXT as the coltype.

To insert binary blobs, use SA_BINARY as the coltype.

Note: The buffer that is passed into this function does not need to be NULL terminated. The size in bytes must be passed in with the chunksize argument, and not count the NULL terminator, if one exists.
If a failure occurs, the Blob insertion mechanism is automatically reset.

Example 1

/* Using the BLOB_ALL flag */
#include "WorkingDialog.h"
...
#define SIZE 2048000
int status;
char *blob;
if(!(blob = (char *)malloc(SIZE)))
	return;
read(file_descriptor, blob, SIZE);
status = SaPutBlob( SGESYBASE, "CEZANNE",
				"pubs2", "blurbs",
				"copy",
				SA_TEXT,
				"where au_id = `192-748-2293'",
				SIZE,
				blob,
				SIZE,
				BLOB_ALL);
free(blob);
if(status == 0)
	printf("Success!\n");
else
	printf("Failure inserting blob.\n");
...

Example 2

/* Using the BLOB_PART and BLOB_DONE flags */
#include "WorkingDialog.h"
...
#define SIZE 1024000
#define BIGSIZE 4*SIZE
int status, i;
char *blob;
if(!(blob = (char *)malloc(BIGSIZE)))
	return;
read(file_descriptor, blob, BIGSIZE);
for(i = 0; i < 4; i++) {
	/* insert first chunk */
	status = SaPutBlob( SGESYBASE, "CEZANNE",
			"pubs2", "blurbs",
			"copy", SA_TEXT,
			"where au_id = `192-748-2293'",
			BIGSIZE,
			blob + (i * SIZE),
			SIZE,
			BLOB_PART);
	if(status) { /* SaPutBlob returned failure status */
		printf("Failure inserting blob.\n");
		free(blob);
		return;
	}
/* reset blob insertion mechanism */
SaPutBlob( SGESYBASE,
			"CEZANNE",
			"pubs2",
			"blurbs",
			"copy",
			SA_TEXT,
			"where au_id = `192-748-2293'",
			BIGSIZE,
			NULL,
			SIZE,
			BLOB_DONE);
free(blob);
printf("Success!\n");
...

See Also



[Top] [Prev] [Next] [Bottom] [Contents]

info@bluestone.com
Copyright © 1997, Bluestone. All rights reserved.